import { ref } from 'vue'
import { getCustomer } from '@/api/user'

/**
 * 获取账号关联的企业服务
 */
export default function () {
  const getCompanyListLoading = ref(false)
  const companyList = ref<AccountAPIResponse.AccountConnectEnterprise>({
    customerRoleVos: [],
    name: '',
    phone: '',
  })

  const getCompanyList = async () => {
    try {
      getCompanyListLoading.value = true
      const res = await getCustomer()
      getCompanyListLoading.value = false
      if (res.data.code === 20000) {
        companyList.value = res.data.data.row
        return ''
      }

      return res.data.message
    } catch (error) {
      getCompanyListLoading.value = false
      return '获取企业失败，请稍后重试'
    }
  }

  return {
    companyList,
    getCompanyListLoading,
    getCompanyList,
  }
}
